﻿using System;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Drawing;
using com.magickms.util;
using System.IO;

namespace com.magickms
{
    public partial class LangRes : Form
    {
        public LangRes()
        {
            InitializeComponent();

            this.Region = Util.ReShape(0, 0, Width, Height, 2, true);
        }

        #region 窗口加载事件
        private void FormPtn_Load(object sender, System.EventArgs e)
        {
            bgTl = Image.FromFile("png/bgtl.png");
            bgTm = Image.FromFile("png/bgtm.png");
            bgTr = Image.FromFile("png/bgtr.png");

            bgMl = Image.FromFile("png/bgml.png");
            bgMm = Image.FromFile("png/bgmm.png");
            bgMr = Image.FromFile("png/bgmr.png");

            bgBl = Image.FromFile("png/bgbl.png");
            bgBm = Image.FromFile("png/bgbm.png");
            bgBr = Image.FromFile("png/bgbr.png");

            _exitD = Image.FromFile(@"png\exitd.png");
            if (File.Exists(@"png\exite.png"))
            {
                _exitE = Image.FromFile(@"png\exite.png");
            }
            if (File.Exists(@"png\exitp.png"))
            {
                _exitP = Image.FromFile(@"png\exitp.png");
            }

            _hideD = Image.FromFile(@"png\hided.png");
            if (File.Exists(@"png\hidee.png"))
            {
                _hideE = Image.FromFile(@"png\hidee.png");
            }
            if (File.Exists(@"png\hidep.png"))
            {
                _hideP = Image.FromFile(@"png\hidep.png");
            }

            _menuD = Image.FromFile(@"png\menud.png");
            if (File.Exists(@"png\menue.png"))
            {
                _menuE = Image.FromFile(@"png\menue.png");
            }
            if (File.Exists(@"png\menup.png"))
            {
                _menuP = Image.FromFile(@"png\menup.png");
            }

            PbExit.Image = _exitD;
            PbHide.Image = _hideD;
            PbMenu.Image = _menuD;

            ReDraw();
        }
        #endregion

        #region 窗口殊效
        //private Color _titleColor = Color.FromArgb(169, 212, 109);
        //private Color _borderColor = Color.FromArgb(169, 212, 109);
        //private Color _contentColor = Color.FromArgb(227, 241, 209);
        //private Color _titleColor = Color.FromArgb(234, 234, 234);
        //private Color _borderColor = Color.FromArgb(178, 178, 178);
        //private Color _contentColor = Color.FromArgb(240, 240, 240);
        //private int _titleHeight = 20;
        //private int _borderWidth = 1;

        /// <summary>
        /// 窗口区域
        /// </summary>
        private Region _formRs;
        /// <summary>
        /// 当前背景
        /// </summary>
        private Image _fromBg;

        /// <summary>
        /// 关闭按钮
        /// </summary>
        private Image _exitD;
        private Image _exitE;
        private Image _exitP;

        /// <summary>
        /// 隐藏按钮
        /// </summary>
        private Image _hideD;
        private Image _hideE;
        private Image _hideP;

        /// <summary>
        /// 选项按钮
        /// </summary>
        private Image _menuD;
        private Image _menuE;
        private Image _menuP;

        /// <summary>
        /// 顶部背景
        /// </summary>
        private Image bgTl;
        private Image bgTm;
        private Image bgTr;

        /// <summary>
        /// 中部背景
        /// </summary>
        private Image bgMl;
        private Image bgMm;
        private Image bgMr;

        /// <summary>
        /// 底部背景
        /// </summary>
        private Image bgBl;
        private Image bgBm;
        private Image bgBr;

        /// <summary>
        /// 窗口重绘
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormPtn_Paint(object sender, PaintEventArgs e)
        {
            //g.FillRectangle(new SolidBrush(_borderColor), 0, 0, Width, Height);
            //g.FillRectangle(new SolidBrush(_titleColor), _borderWidth, _borderWidth, Width - _borderWidth * 2, _titleHeight);
            //g.FillRectangle(new SolidBrush(_contentColor), _borderWidth, _titleHeight + _borderWidth, Width - _borderWidth * 2, Height - _titleHeight - _borderWidth * 3);
            //this.Region = _formDim;

            e.Graphics.DrawImage(_fromBg, 0, 0);
        }

        /// <summary>
        /// 窗口调整大小
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormPtn_Resize(object sender, System.EventArgs e)
        {
            this.Region = _formRs;
        }

        private void ReDraw()
        {
            _fromBg = new Bitmap(Width, Height);
            Graphics g = Graphics.FromImage(_fromBg);

            int x = 0;
            int y = 0;
            int w = Width - bgTr.Width;
            DoDraw(g, bgTl, bgTm, bgTr, x, y, w);

            x = 0;
            y += bgTl.Height;
            w = Width - bgMr.Width;
            DoDraw(g, bgMl, bgMm, bgMr, x, y, w);

            int h = Height - bgBl.Height;
            while (y < h)
            {
                x = 0;
                y += bgMl.Height;
                DoDraw(g, bgMl, bgMm, bgMr, x, y, w);
            }

            x = 0;
            y = h;
            w = Width - bgBr.Width;
            DoDraw(g, bgBl, bgBm, bgBr, x, y, w);
        }

        private void DoDraw(Graphics g, Image imgL, Image imgM, Image imgR, int x, int y, int w)
        {
            g.DrawImage(imgL, x, y);

            x += imgL.Width;
            g.DrawImage(imgM, x, y);

            while (x < w)
            {
                x += imgM.Width;
                g.DrawImage(imgM, x, y);
            }

            g.DrawImage(imgR, w, y);
        }

        #region Menu按钮
        private void PbMenu_MouseEnter(object sender, System.EventArgs e)
        {
            if (_menuE != null)
            {
                PbMenu.Image = _menuE;
            }
        }

        private void PbMenu_MouseLeave(object sender, System.EventArgs e)
        {
            if (_menuE != null)
            {
                PbMenu.Image = _menuD;
            }
        }

        private void PbMenu_MouseDown(object sender, MouseEventArgs e)
        {
            if (_menuP != null)
            {
                PbMenu.Image = _menuP;
            }
        }

        private void PbMenu_MouseUp(object sender, MouseEventArgs e)
        {
            if (_menuE != null)
            {
                PbMenu.Image = _menuE;
            }
        }

        private void PbMenu_Click(object sender, System.EventArgs e)
        {

        }
        #endregion

        #region Hide按钮
        private void PbHide_MouseEnter(object sender, System.EventArgs e)
        {
            if (_hideE != null)
            {
                PbHide.Image = _hideE;
            }
        }

        private void PbHide_MouseLeave(object sender, System.EventArgs e)
        {
            if (_hideE != null)
            {
                PbHide.Image = _hideD;
            }
        }

        private void PbHide_MouseDown(object sender, MouseEventArgs e)
        {
            if (_hideP != null)
            {
                PbHide.Image = _hideP;
            }
        }

        private void PbHide_MouseUp(object sender, MouseEventArgs e)
        {
            if (_hideE != null)
            {
                PbHide.Image = _hideE;
            }
        }

        private void PbHide_Click(object sender, System.EventArgs e)
        {
            WindowState = FormWindowState.Minimized;
        }
        #endregion

        #region Exit按钮
        private void PbExit_MouseEnter(object sender, System.EventArgs e)
        {
            if (_exitE != null)
            {
                PbExit.Image = _exitE;
            }
        }

        private void PbExit_MouseLeave(object sender, System.EventArgs e)
        {
            if (_exitE != null)
            {
                PbExit.Image = _exitD;
            }
        }

        private void PbExit_MouseDown(object sender, MouseEventArgs e)
        {
            if (_exitP != null)
            {
                PbExit.Image = _exitP;
            }
        }

        private void PbExit_MouseUp(object sender, MouseEventArgs e)
        {
            if (_exitE != null)
            {
                PbExit.Image = _exitE;
            }
        }

        private void PbExit_Click(object sender, System.EventArgs e)
        {
            Visible = false;
        }
        #endregion

        private void CbCategory_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
        #endregion
    }
}
